package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GridAccount;
import com.ruoyi.system.service.IGridAccountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 密码管理Controller
 * 
 * @author ruoyi
 * @date 2021-12-30
 */
@RestController
@RequestMapping("/system/account")
public class GridAccountController extends BaseController
{
    @Autowired
    private IGridAccountService gridAccountService;

    /**
     * 查询密码管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:account:list')")
    @GetMapping("/list")
    public TableDataInfo list(GridAccount gridAccount)
    {
        startPage();
        List<GridAccount> list = gridAccountService.selectGridAccountList(gridAccount);
        return getDataTable(list);
    }

    /**
     * 导出密码管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:account:export')")
    @Log(title = "密码管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GridAccount gridAccount)
    {
        List<GridAccount> list = gridAccountService.selectGridAccountList(gridAccount);
        ExcelUtil<GridAccount> util = new ExcelUtil<GridAccount>(GridAccount.class);
        util.exportExcel(response, list, "密码管理数据");
    }

    /**
     * 获取密码管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:account:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Integer userId)
    {
        return AjaxResult.success(gridAccountService.selectGridAccountByUserId(userId));
    }

    /**
     * 新增密码管理
     */
    @PreAuthorize("@ss.hasPermi('system:account:add')")
    @Log(title = "密码管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GridAccount gridAccount)
    {
        return toAjax(gridAccountService.insertGridAccount(gridAccount));
    }

    /**
     * 修改密码管理
     */
    @PreAuthorize("@ss.hasPermi('system:account:edit')")
    @Log(title = "密码管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GridAccount gridAccount)
    {
        return toAjax(gridAccountService.updateGridAccount(gridAccount));
    }

    /**
     * 删除密码管理
     */
    @PreAuthorize("@ss.hasPermi('system:account:remove')")
    @Log(title = "密码管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Integer[] userIds)
    {
        return toAjax(gridAccountService.deleteGridAccountByUserIds(userIds));
    }
}
